﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace z.Controllers {
	public class SupportController : Controller {
		
		static Dictionary<string,m.Messenger> Mess = new Dictionary<string,m.Messenger>();

		public ActionResult Index() {
			Session["realtime"] = true;
			return View(Mess);
		}

		public ActionResult _Show(string ID) {
			if (Mess.ContainsKey(ID)) {
				ViewBag.ID=ID;
				return View(Mess[ID]);
			} else
				return null;
		}

		[Authorize]
		public ActionResult _Edit(string msg) {
			int num = Mess.Keys.Count();
			if (num > 100) {
				var keys = Mess.Keys.Take(100 - num).ToList();
				foreach (var x in keys) {
					Mess.Remove(x);
				}
			}
			var u=App.db.UserProfiles.Where(x => x.UserName == User.Identity.Name).Single();
			var str=DateTime.Now.ToString("yyMMddhhmmssFFFF");
			WebSocketController.SendMessenger("Support,"+str);
			Mess.Add(str,
				new m.Messenger(
					u,
					msg));
			return null;
		}
	}
}
